﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickApp.Core.Models;

namespace QuickApp.Core
{
    /// <summary>
    /// Model实体的扩展类和公共方法
    /// </summary>
    public static class ModelExtensions
    {
        /// <summary>
        /// 设置全路径
        /// </summary>
        /// <param name="tree"></param>
        /// <param name="parentFullPath">父节点的全路径</param>
        public static void SetFullPath(this ITreeModel tree, string parentFullPath)
        {
            if (string.IsNullOrEmpty(tree.ParentId))
            {
                tree.FullPath = GetFullPath(string.Empty, tree.Id);
            }
            else
            {
                tree.FullPath = GetFullPath(parentFullPath, tree.Id);
            }
        }

        /// <summary>
        /// 获取全路径
        /// </summary>
        /// <param name="parentFullId">父节点的全路径</param>
        /// <param name="Id">本节点的Id</param>
        /// <returns></returns>
        private static string GetFullPath(string parentFullId, string Id)
        {
            if (string.IsNullOrEmpty(parentFullId))
            {
                return Id;
            }
            else
            {
                return parentFullId + ModelConstant.FULL_PATH_SEPARATOR + Id;
            }
        }
    }
}
